
$(document).ready(function () {
	$("#ALERTA_PAGO").height($("#PRINCIPAL").height());
	$("#ALERTA_PRODUCTO").height($("#PRINCIPAL").height());
	$("menuItem").Tooltip({delay:0, track:true});
});
function div_visible(_s_div, _s_div_visible) {
	var v_div = document.getElementById(_s_div);
	if (_s_div_visible !== null) {
		v_div.style.display = (v_div.style.display == "none") ? "block" : "none";
	} else {
		v_div.style.display = (_s_div_visible === true) ? "block" : "none";
	}
}
function prompt_nuevo(mensaje) {
	var resultado = "";
	while (true) {
		resultado = window.prompt(mensaje, resultado);
		if (resultado === null || 0 < resultado.trim().length) {
			return resultado;
		}
	}
}
function obtenerTextOpcion(theSel, posicion) {
	return theSel.options[posicion].text;
}
function obtenerValueOpcion(theSel, posicion) {
	return theSel.options[posicion].value;
}
function agregarOpcion(theSel, theText, theValue) {
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}
function eliminarOpcion(theSel, posicion) {
	var options = theSel.options;
	theSel.options.length = 0;
	var j = 0;
	for (var k = 0; k < options.length; k = k + 1) {
		if (k != posicion) {
			theSel.options[j] = options[k];
			j = j + 1;
		}
	}
}
function selecionarTodosOpcion(theSel) {
	var selLength = theSel.length;
	var i;
	for (i = selLength - 1; i >= 0; i = i - 1) {
		theSel.options[i].selected = true;
	}
}
function selecionarSelect(theSel) {
	var selLength = theSel.length;
	var i;
	for (i = selLength - 1; i >= 0; i = i - 1) {
		theSel.options[i].selected = true;
	}
}
function select_option(_s_select) {
	var variable = 0;
	try {
		variable = _s_select.options[_s_select.selectedIndex].value;
	}
	catch (e) {
	}
	return variable;
}
function select_option_valor(_s_select, _s_value) {
	var options = _s_select.options;
	for (var k = 0; k < options.length; k = k + 1) {
		if (_s_select.options[k].value == _s_value) {
			_s_select.options[k].selected = true;
		}
	}
}
function found_option_valor(_s_select, _s_value) {
	var options = _s_select.options;
	for (var k = 0; k < options.length; k = k + 1) {
		if (_s_select.options[k].value == _s_value) {
			return true;
		}
	}
	return false;
}
function found_posicion_option_valor(_s_select, _s_value) {
	var options = _s_select.options;
	for (var k = 0; k < options.length; k = k + 1) {
		if (_s_select.options[k].value == _s_value) {
			return k;
		}
	}
	return -1;
}
String.prototype.trim = function () {
	return this.replace(/\s+$|^\s+/g, "");
};
String.prototype.estaUndefined = function () {
	return typeof this == "undefined";
};
function peticionAjax() {
	var xmlhttp = false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest != "undefined") {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function _validarInteger(s_valor) {
	var i = parseInt(s_valor);
	if (!i || i < 0) {
		return 0;
	}
	return i;
}
function _validarInputInteger(s_inp) {
	s_inp.value = _validarInteger(s_inp.value);
}
function _validarInputDouble(s_inp) {
	s_inp.value = fn_round(_validarDouble(s_inp.value), 2);
}
function _validarDouble(s_valor) {
	var variable = 0;
	try {
		if (!isNaN(parseFloat(s_valor))) {
			variable = parseFloat(s_valor);
		}
	}
	catch (e) {
		alert(e);
	}
	if (variable < 0) {
		variable = 0;
	}
	return variable;
}
function esnumero(campo) {
	return (!(isNaN(campo)));
}
function fn_round(numero, decimales) {
	var cant_dec = Math.pow(10, parseInt(decimales));
	var new_numero = Math.round(parseFloat(numero) * parseInt(cant_dec)) / parseInt(cant_dec);
	var nume1 = new oNumero(new_numero);
	var final_numero = nume1.formato(2, true);
	return final_numero;
}
function oNumero(numero) {
	this.valor = numero || 0;
	this.dec = -1;
	this.formato = numFormat;
	this.ponValor = ponValor;
	function ponValor(cad) {
		if (cad == "-" || cad == "+") {
			return;
		}
		if (cad.length === 0) {
			return;
		}
		if (cad.indexOf(".") >= 0) {
			this.valor = parseFloat(cad);
		} else {
			this.valor = parseInt(cad);
		}
	}
	function numFormat(dec, miles) {
		var num = this.valor, signo = 3, expr;
		var cad = "" + this.valor;
		var ceros = "", pos, pdec, i;
		for (i = 0; i < dec; i = i + 1) {
			ceros += "0";
		}
		pos = cad.indexOf(".");
		if (pos < 0) {
			cad = cad + "." + ceros;
		} else {
			pdec = cad.length - pos - 1;
			if (pdec <= dec) {
				for (i = 0; i < (dec - pdec); i = i + 1) {
					cad += "0";
				}
			} else {
				num = num * Math.pow(10, dec);
				num = Math.round(num);
				num = num / Math.pow(10, dec);
				cad = new String(num);
			}
		}
		pos = cad.indexOf(".");
		if (pos < 0) {
			pos = cad.lentgh;
		}
		if (cad.substr(0, 1) == "-" || cad.substr(0, 1) == "+") {
			signo = 4;
		}
		if (miles && pos > signo) {
			do {
				expr = /([+-]?\d)(\d{3}[\.\,]\d*)/;
				cad.match(expr);
				cad = cad.replace(expr, RegExp.$1 + "" + RegExp.$2);
			} while (cad.indexOf(",") > signo);
		}
		if (dec < 0) {
			cad = cad.replace(/\./, "");
		}
		return cad;
	}
}
function validarDoubleInput(s_input) {
	s_input.value = _validarDouble(s_input.value);
}
function validarIntegerInput(s_input) {
	s_input.value = _validarInteger(s_input.value);
}
function validarStringInput(s_input) {
	s_input.value = s_input.value.trim();
}
function aref(s_ref) {
	document.location = s_ref;
}
function xGetContextPath() {
	var context = "";
	var loct = document.location;
	var array = loct.href.split("/");
	try {
		context = array[0] + "/" + array[1] + "/" + array[2] + "/" + array[3];
	}
	catch (e) {
	}
	return context;
}
function _validarPorcentaje(s_input) {
	if (s_input.value > 100) {
		s_input.value = 100;
		return;
	}
	if (s_input.value < 0) {
		s_input.value = 0;
		return;
	}
}
function mensaje_error(s_mensaje, s_tipo) {
	if (null != s_mensaje && 0 < s_mensaje.length) {
		$("#txtError").html(s_mensaje);
		$("#div_txtError").center({vertical:false, horizontal:true});
		$("#div_txtError").fadeIn("slow");
		$("#div_txtError").css("position", "fixed");
		if (null != s_tipo) {
			$("#txtError").css("color", "#FFFFFF");
			$("#td_txtError11").css("backgroundImage", "url('" + xGetContextPath() + "/images/punto_rojo.png')");
			$("#td_txtError12").css("backgroundColor", "#CC0000");
			$("#td_txtError13").css("backgroundImage", "url('" + xGetContextPath() + "/images/punto_rojo.png')");
			$("#td_txtError21").css("backgroundColor", "#CC0000");
			$("#td_txtError22").css("backgroundColor", "#CC0000");
			$("#td_txtError23").css("backgroundColor", "#CC0000");
			$("#td_txtError31").css("backgroundImage", "url('" + xGetContextPath() + "/images/punto_rojo.png')");
			$("#td_txtError32").css("backgroundColor", "#CC0000");
			$("#td_txtError33").css("backgroundImage", "url('" + xGetContextPath() + "/images/punto_rojo.png')");
		} else {
			$("#txtError").css("color", "#000000");
			$("#td_txtError11").css("backgroundImage", "url('" + xGetContextPath() + "/images/punto_amarillo.png')");
			$("#td_txtError12").css("backgroundColor", "#FFF1A8");
			$("#td_txtError13").css("backgroundImage", "url('" + xGetContextPath() + "/images/punto_amarillo.png')");
			$("#td_txtError21").css("backgroundColor", "#FFF1A8");
			$("#td_txtError22").css("backgroundColor", "#FFF1A8");
			$("#td_txtError23").css("backgroundColor", "#FFF1A8");
			$("#td_txtError31").css("backgroundImage", "url('" + xGetContextPath() + "/images/punto_amarillo.png')");
			$("#td_txtError32").css("backgroundColor", "#FFF1A8");
			$("#td_txtError33").css("backgroundImage", "url('" + xGetContextPath() + "/images/punto_amarillo.png')");
		}
	} else {
		$("#div_txtError").fadeOut("slow");
		return;
	}
}
function ver_div_alerta_pagos() {
	$("#div_alerta_pagos").height($("#ALERTA").height() - 62);
	$("#div_alerta_productos").fadeOut("fast");
	$("#div_alerta_pagos").fadeIn("slow");
}
function ver_div_alerta_productos() {
	$("#div_alerta_productos").height($("#ALERTA").height() - 62);
	$("#div_alerta_pagos").fadeOut("fast");
	$("#div_alerta_productos").fadeIn("slow");
}
function isFechaPrimerMayor(fecha1, fecha2) {
	if (fecha1 === null || fecha2 === null) {
		return false;
	} else {
		try {
			f1 = fecha1.split("/");
			f2 = fecha2.split("/");
			d1 = parseInt(f1[0], 10);
			m1 = parseInt(f1[1], 10);
			a1 = parseInt(f1[2], 10);
			d2 = parseInt(f2[0], 10);
			m2 = parseInt(f2[1], 10);
			a2 = parseInt(f2[2], 10);
			if (a1 > a2) {
				return true;
			}
			if (a1 == a2) {
				if (m1 > m2) {
					return true;
				}
				if ((m1 == m2) && (d1 >= d2)) {
					return true;
				}
				return false;
			}
		}
		catch (e) {
			return false;
		}
		return false;
	}
	return false;
}

